<?php
/**
 * @description : show the email list when send list.
 * @class-name : GetDailyEmailsList()
 * @author : stephen.mo <stephen.mo@achievo.com>
 * @date : 2010-04-12
 */

class GetDailyEmailsList extends BaseAction{ 

    private function getEmailList() {
        $result = array();
        $rows = (isset($_GET['rows'])) ? $_GET['rows'] : 5;
        $sord = (isset($_GET['sord'])) ? $_GET['sord'] : 'desc';
        $sidx = (isset($_GET['sidx'])) ? $_GET['sidx'] : 'id';
        $page = (isset($_GET['page'])) ? $_GET['page'] : 1;
        $data = DailyEmailListModel::getInstance()->getEmailList($page,$sidx,$rows,$sord);
        $result['page'] = $page;
        $result['total'] = ceil($data['total']/$rows);
        $result['records'] = $data['total'];
        $result['rows'] = $data['data'];
        return json_encode($result);
    }

    private function addEmailList() {
        $name = $_REQUEST['name'];
        $email = $_REQUEST['email'];
        $result = DailyEmailListModel::getInstance()->addEmailList($name,$email);
        return $result;
    }
    
    private function editEmailList() {
        $id = $_REQUEST['id'];
        $name = $_REQUEST['name'];
        $email = $_REQUEST['email'];
        $return = DailyEmailListModel::getInstance()->editEmailList($id,$name,$email);
        return $return;
    }

    private function delEmailList() {
        $id = $_REQUEST['id'];
        $return = DailyEmailListModel::getInstance()->delEmailList($id);
        return $return;
    }

    private function editsEmailList() {
        $act = $_REQUEST['oper'];
        if (empty($act)) return true;
        $sub_method = $act.'EmailList';
        $data = $this->{$sub_method}();
        return $data;
    }
                                    
    public function execute() {
        $opt = $_GET['opt'];
        if (empty($opt)) {
            echo null;
            die();
        }
        $method_name = $opt.'EmailList';
        if (!method_exists($this,$method_name)) {
            echo null;
            die();
        }
        $data = $this->{$method_name}();
        echo $data;
        die();
    }
}

?>